package com.glorysoft.lipuxinpda.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.glorysoft.lipuxinpda.R;
import com.glorysoft.lipuxinpda.adapter.DieListAdapter;
import com.glorysoft.lipuxinpda.adapter.MaterialAdapter;
import com.glorysoft.lipuxinpda.adapter.RealTimeRecyclerViewAdapter;
import com.glorysoft.lipuxinpda.base.BaseActivity;
import com.glorysoft.lipuxinpda.base.Constant;
import com.glorysoft.lipuxinpda.entity.BaseEntity;
import com.glorysoft.lipuxinpda.entity.EqpInfoEntity;
import com.glorysoft.lipuxinpda.entity.EqpMessageInfo;
import com.glorysoft.lipuxinpda.entity.LoginEntity;
import com.glorysoft.lipuxinpda.entity.MaterialInfoEntity;
import com.glorysoft.lipuxinpda.entity.MessageInfoEntity;
import com.glorysoft.lipuxinpda.entity.RealTimeMessageReturnEntity;
import com.glorysoft.lipuxinpda.entity.ResponseEntity;
import com.glorysoft.lipuxinpda.entity.StartProcessReturnEntity;
import com.glorysoft.lipuxinpda.utils.GsonUtils;
import com.glorysoft.lipuxinpda.utils.NetUtils;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.activity_public.FreeUI_QRCodeActivity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

public class BatchWorkBeginActivity extends BaseActivity implements View.OnClickListener {
    private Context mContext;

    private LinearLayout llMain;
    private LinearLayout llMaterialLayout;

    private TextView tv_eqp_no;//设备号
    private TextView tv_eqp_state;//设备状态
    private TextView tv_lot_id;//批次号
    private TextView tv_lot_qty_chip;//数量
    private TextView tv_station;//当前站点
    private TextView tv_product_model;//产品型号
    private TextView tv_product_type;//封装形式
    private TextView tv_die_type;//芯片型号
    private TextView tv_wafersource_model;//晶圆批号
    private TextView tv_pro_name;//焊接图
    private TextView tv_pro_version;//焊接图版本

    private FreeUI_ClearEditText et_Lot;//流程卡号

    private RecyclerView rvMaterialList;//应使用的物料
    private RecyclerView rv_realtime_message;//实时消息

    private Button btn_query;//查看物料信息
    private Button btn_scan;//扫描lot
    private Button btn_deleteLot;//删除预扫描
    private Button btn_con;


    private NestedScrollView scroll_view;

    private String sEqpID = "";//设备号
    private List<MaterialInfoEntity> mMaterialInfoList = null;//应使用的物料
    private MaterialAdapter materialAdapter;//应上物料适配器
    private RealTimeRecyclerViewAdapter mRealTimeRecyclerViewAdapter;//实时消息适配器

    private EqpInfoEntity mEqpInfoEntity;//设备信息

    private FreeUI_GeneralFragmentDialog mDieTypeDialog;

    private String IS_MANUAL_MODE = "N";//是否开始作业

    private FreeUI_GeneralFragmentDialog mMessageDialog;//消息提示框

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();
        getEqpInfo("true");//获取设备信息

        // region 测试
//        String sJSON = "{\n" +
//                "   \"data\":{\n" +
//                "    \"EQP_ID\":\"2FS106\",\n" +
//                "\"EQP_TYPE\":\"DAD3350\",\n" +
//                "    \"CUR_USERID\":\"K3342\",\n" +
//                "    \"CURRENT_EQP_STATE\":\"IDLE\",\n" +
//                "    \"IS_MANUAL_MODE\":true,\n" +
//                "    \"LOT_ID\":\"LA111\",\n" +
//                "    \"LOT_QTY_CHIP\":\"1111\",\t\n" +
//                "    \"DEVICE\":\"TST\",\n" +
//                "    \"WAFERSOURCE\":\"T111\",\n" +
//                "    \"RECIPE\":\"TEST_PPID\",\n" +
//                "    \"PROC_68A_ID\":\"EAP_TEST_PPID\",\n" +
//                "    \"DIESEQ\":\"2\",\n" +
//                "    \"IS_STARTED\":\"Y\",\n" +
//                "    \"MATERIALLIST\":[\n" +
//                "     {\n" +
//                "\t\t\"MATERIAL_TYPE\":\"HubBlade\",\n" +
//                "               \"MATERIAL_MODEL\":\"ZH05-SD3000-N1-50 BB R1\"\n" +
//                "      },\n" +
//                "\t{\n" +
//                "\t\t\"MATERIAL_TYPE\":\"HubBlade\",\n" +
//                "               \"MATERIAL_MODEL_YZ2\":\"ZH05-SD3000-N1-50 BB R1\"\n" +
//                "      }\n" +
//                "    ]\n" +
//                "}\n" +
//                "   \n" +
//                "}";
//        try {
//            JSONObject jsonObject = new JSONObject(sJSON);
//            String sData = jsonObject.getString("data");
//            mEqpInfoEntity = GsonUtils.getObject(sData, EqpInfoEntity.class);
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }

//        showEqpInfo();//显示设备信息


//        String data = "{\n" +
//                "     \"data\":{\n" +
//                "        \"EQPID\":\"2FS101\",\n" +
//                "        \"MessageList\":[\n" +
//                "            {\n" +
//                "                \"CREATED_TIME\":\"2020/10/11 14:11:11\",\n" +
//                "                \"OPERAND\":\"PDA\",\n" +
//                "                \"OPERATION_CONTENT\":\"点击批次开始按钮\",\n" +
//                "                \"MSG_ID\":\"1111\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"CREATED_TIME\":\"2020/10/11 14:21:11\",\n" +
//                "                \"OPERAND\":\"PDA\",\n" +
//                "                \"OPERATION_CONTENT\":\"设备开始作业\",\n" +
//                "                \"MSG_ID\":\"1121\"\n" +
//                "             }]}}";
//        try {
//            JSONObject jsonObject = new JSONObject(data);
//            String sData = jsonObject.getString("data");
//            RealTimeMessageReturnEntity body = GsonUtils.getObject(sData, RealTimeMessageReturnEntity.class);
//            showRealTimeMessage(body);//显示实时消息
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
        //endregion

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_batch_work_begin;
    }

    @Override
    protected void initView() {
        mContext = this;

        llMain = findViewById(R.id.llMain);
        llMaterialLayout = findViewById(R.id.llMaterialLayout);

        tv_die_type = findViewById(R.id.tv_die_type);
        tv_eqp_state = findViewById(R.id.tv_eqp_state);
        tv_eqp_no = findViewById(R.id.tv_eqp_no);
        tv_lot_id = findViewById(R.id.tv_lot_id);
        tv_lot_qty_chip = findViewById(R.id.tv_lot_qty_chip);
        tv_pro_name = findViewById(R.id.tv_pro_name);
        tv_product_model = findViewById(R.id.tv_product_model);
        tv_product_type = findViewById(R.id.tv_product_type);
        tv_pro_version = findViewById(R.id.tv_pro_version);
        tv_wafersource_model = findViewById(R.id.tv_wafersource_model);
        tv_station = findViewById(R.id.tv_station);

        et_Lot = findViewById(R.id.et_Lot);

        rvMaterialList = findViewById(R.id.rvMaterialList);
        rv_realtime_message = findViewById(R.id.rv_realtime_message);

        btn_query = findViewById(R.id.btn_query);
        btn_scan = findViewById(R.id.btn_scan);
        btn_con = findViewById(R.id.btn_con);

        btn_deleteLot = findViewById(R.id.btn_deleteLot);

        scroll_view = findViewById(R.id.scroll_view);

        btn_query.setOnClickListener(this);
        btn_scan.setOnClickListener(this);
        btn_con.setOnClickListener(this);
        btn_deleteLot.setOnClickListener(this);
        llMaterialLayout.setOnClickListener(this);
        tv_die_type.setOnClickListener(this);


    }

    @Override
    protected void initData() {
        Bundle extras = getIntent().getExtras();
        sEqpID = extras.getString("EQPID");


    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        freeUI_titleView.setTitle(getString(R.string.batchStartOperation));
        freeUI_titleView.setRightListener(getString(R.string.startWork), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mEqpInfoEntity.getIS_STARTED() == true) {
                    showDialog("批次已处于作业中，不能再次开始", false);
                } else {
                    if (IS_MANUAL_MODE.equals("Y")) {
                        showDialog("批次已处于作业中，不能再次开始", false);
                    } else {
                        startProcess();
                    }
                }
            }
        });
        return new FreeUI_AddViewEntity(getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY), llMain);
    }

    //region 接口调用

    //获取设备信息
    private void getEqpInfo(String isFirst ) {
        FreeUI_EntityCallBack<BaseEntity<EqpInfoEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<EqpInfoEntity>>(new TypeToken<BaseEntity<EqpInfoEntity>>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity<EqpInfoEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    showToast(response.body().getMessage(), true);
                    mEqpInfoEntity = response.body().getData().getBody();
                    //更改物料后重新调用一遍该接口,更新物料信息
                    if (!TextUtils.isEmpty(mEqpInfoEntity.getDIE_TYPE())) {
                        String die_type = mEqpInfoEntity.getDIE_TYPE();
                        mEqpInfoEntity = response.body().getData().getBody();
                        mEqpInfoEntity.setDIE_TYPE(die_type);
                    }
                    showEqpInfo();//显示设备信息
                    getRealTimeMessage();//获取实时消息
                }
            }

            @Override
            public void onError(Response<BaseEntity<EqpInfoEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "PDAEQPInfo");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        map.put("ISFIRST", isFirst);
        String method = Constant.INSTANCE.getNET_URL() + "/PDAEQPInfoRequest";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }


    //扫描LOT信息-获取芯片类型
    private void getLotInfo(String lotId) {
        FreeUI_EntityCallBack<BaseEntity<EqpInfoEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<EqpInfoEntity>>(new TypeToken<BaseEntity<EqpInfoEntity>>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity<EqpInfoEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    showToast(response.body().getMessage(), true);
                    EqpInfoEntity eqpInfoEntity = response.body().getData().getBody();
                    if(eqpInfoEntity.getDIE_TYPE().length()>0 && eqpInfoEntity.getDIE_TYPE().contains(";")){
                        //String[] die = eqpInfoEntity.getDIE_TYPE().split(";");
                        showDieType();//显示晶片型号
                        mEqpInfoEntity.setDIE_TYPE(eqpInfoEntity.getDIE_TYPE());
                    }else{
                        getEqpInfo("false");
                    }
                }
            }

            @Override
            public void onError(Response<BaseEntity<EqpInfoEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "ShowEqpInfo");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        map.put("LOT_ID", lotId);//批次号
        String method = Constant.INSTANCE.getNET_URL() + "/ShowLotInfoRequest";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }

    //更改芯片类型
    private void changeDie(String sDie) {
        FreeUI_EntityCallBack<BaseEntity> callBack = new FreeUI_DialogEntityCallBack<BaseEntity>(new TypeToken<BaseEntity>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    showToast(response.body().getMessage(), true);
                }
            }

            @Override
            public void onError(Response<BaseEntity> response) {
                super.onError(response);
                loadError(response.getException(), "ChangeDie");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        map.put("LOT_BARCODE", mEqpInfoEntity.getLOT_ID());//批次
        map.put("SEL_DIESEQ", sDie);//晶片类型

        String method = Constant.INSTANCE.getNET_URL() + "/ChangeDie";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }

    //开始作业
    private void startProcess() {
        FreeUI_EntityCallBack<BaseEntity<StartProcessReturnEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<StartProcessReturnEntity>>(new TypeToken<BaseEntity<StartProcessReturnEntity>>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity<StartProcessReturnEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    StartProcessReturnEntity body = response.body().getData().getBody();
                    IS_MANUAL_MODE = body.getIS_MANUAL_MODE();
                    if (IS_MANUAL_MODE.equals("Y")) {
                        showToast(response.body().getMessage(), true);
                    } else {
                        showMessageDialog(response.body().getMessage());
                    }
                }
            }

            @Override
            public void onError(Response<BaseEntity<StartProcessReturnEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "StartProcess");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        map.put("LOT_ID", mEqpInfoEntity.getLOT_ID());//批次

        String method = Constant.INSTANCE.getNET_URL() + "/StartProcessRequest";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }

    //获取实时消息
    private void getRealTimeMessage() {
        FreeUI_EntityCallBack<BaseEntity<RealTimeMessageReturnEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<RealTimeMessageReturnEntity>>(new TypeToken<BaseEntity<RealTimeMessageReturnEntity>>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity<RealTimeMessageReturnEntity>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    showToast(response.body().getMessage(), true);

                    RealTimeMessageReturnEntity body = response.body().getData().getBody();
                    showRealTimeMessage(body);//显示实时消息
                }
            }

            @Override
            public void onError(Response<BaseEntity<RealTimeMessageReturnEntity>> response) {
                super.onError(response);
                loadError(response.getException(), "RealTimeMessage");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        String method = Constant.INSTANCE.getNET_URL() + "/RealTimeMessageRequest";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }
    //删除预扫描LOT
    private void requestDeleteLotInfo(String lotid) {
        FreeUI_EntityCallBack<BaseEntity<EqpMessageInfo>> callBack = new FreeUI_DialogEntityCallBack<BaseEntity<EqpMessageInfo>>(new TypeToken<BaseEntity<StartProcessReturnEntity>>() {
        }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<BaseEntity<EqpMessageInfo>> response) {
                super.onSuccess(response);
                if (response.body().isSuccess(getSupportFragmentManager())) {
                    //刷新扫描设备方法
                    getEqpInfo("false");
                }
            }

            @Override
            public void onError(Response<BaseEntity<EqpMessageInfo>> response) {
                super.onError(response);
                loadError(response.getException(), "StartProcess");
            }
        };

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("EQP_ID", sEqpID);//设备号
        map.put("CUR_USERID", Constant.INSTANCE.getLoginEntity().getWORK_NO());//工号
        map.put("LOT_ID", mEqpInfoEntity.getLOT_ID());//批次

        String method = Constant.INSTANCE.getNET_URL() + "/ClearLotInfoRequest";
        new NetUtils().requestPostNetNews(method, this, map, callBack);
    }


    //endregion

    //显示实时消息
    private void showRealTimeMessage(RealTimeMessageReturnEntity entity) {
        if (entity != null && entity.getMessageList() != null && entity.getMessageList().size() >0){
            List<MessageInfoEntity> messageList = entity.getMessageList();
            mRealTimeRecyclerViewAdapter = new RealTimeRecyclerViewAdapter();

            rv_realtime_message.setLayoutManager(new LinearLayoutManager(getBaseContext(), LinearLayoutManager.VERTICAL, false));
            rv_realtime_message.setAdapter(mRealTimeRecyclerViewAdapter);
            mRealTimeRecyclerViewAdapter.setmList(messageList);
        }
    }

    //显示应使用物料
    private void showMaterialInfo() {
        materialAdapter = new MaterialAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        rvMaterialList.setLayoutManager(linearLayoutManager);
        rvMaterialList.setAdapter(materialAdapter);
        materialAdapter.setmList(mMaterialInfoList);

    }

    //显示设备信息
    private void showEqpInfo() {
        tv_eqp_no.setText(sEqpID);
        if (mEqpInfoEntity != null) {
            sEqpID = mEqpInfoEntity.getEQP_ID() == null ? sEqpID : mEqpInfoEntity.getEQP_ID();
            tv_eqp_no.setText(mEqpInfoEntity.getEQP_ID() == null ? "" : mEqpInfoEntity.getEQP_ID());
            tv_eqp_state.setText(mEqpInfoEntity.getCURRENT_EQP_STATE() == null ? "" : mEqpInfoEntity.getCURRENT_EQP_STATE());//设备状态
            tv_lot_id.setText(mEqpInfoEntity.getLOT_ID() ==null ? "" : mEqpInfoEntity.getLOT_ID());//lot id
            tv_lot_qty_chip.setText(mEqpInfoEntity.getLOT_QTY_CHIP() == null ? "" : mEqpInfoEntity.getLOT_QTY_CHIP());//数量
            tv_product_model.setText(mEqpInfoEntity.getPRODUCT_MODEL() == null ? "" :mEqpInfoEntity.getPRODUCT_MODEL());//产品类型
            tv_wafersource_model.setText(mEqpInfoEntity.getWAFERSOURCE_MODEL() == null ? "" : mEqpInfoEntity.getWAFERSOURCE_MODEL());//晶圆批号
            tv_pro_name.setText(mEqpInfoEntity.getPRO_NAME() == null ? "" : mEqpInfoEntity.getPRO_NAME());//焊线图号
            tv_pro_version.setText(mEqpInfoEntity.getPOR_V() == null ? "" : mEqpInfoEntity.getPOR_V());//焊线图版本
            tv_station.setText(mEqpInfoEntity.getLOT_STATION() == null ? "" : mEqpInfoEntity.getLOT_STATION());
            tv_product_type.setText(mEqpInfoEntity.getPACKAGE_TYPE() == null ? "" : mEqpInfoEntity.getPACKAGE_TYPE());//封装形式
            //mMaterialInfoList = mEqpInfoEntity.getMATERIALLIST();//应使用物料
            //showMaterialInfo();//显示应使用物料
        }
    }

    //显示晶片型号
    private void showDieType() {
        String dieType = mEqpInfoEntity.getDIE_TYPE();
        if (dieType.equals("")) {
            return;
        }
        String[] split = dieType.split(";");
        if (split.length == 1) {
            tv_die_type.setText(split[0]);
            changeDie(tv_die_type.getText().toString());
        } else {
            showDieTypeDialog(split);
        }
    }

    //晶片类型选择框
    private void showDieTypeDialog(String[] splite) {
        mDieTypeDialog = new FreeUI_GeneralFragmentDialog();
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_check_die, null);
        Button btn_cancel = view.findViewById(R.id.btn_cancel);
        ListView lv_data = view.findViewById(R.id.lv_die_type);
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDieTypeDialog.dismiss();
            }
        });
        mDieTypeDialog.setLayout(view);
//        mDieTypeDialog.getDialog().setCanceledOnTouchOutside(false);
        mDieTypeDialog.show(getSupportFragmentManager(), "dieTypeSelect");
        mDieTypeDialog.setCallBack(new FreeUI_CommonCallback() {
            @Override
            public void onSuccess() {
                mDieTypeDialog = null;
            }
        });
        DieListAdapter dieListAdapter = new DieListAdapter(mContext, splite);
        lv_data.setAdapter(dieListAdapter);

        lv_data.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                tv_die_type.setText(splite[position]);
                mDieTypeDialog.dismiss();
                changeDie(splite[position]);
            }
        });
    }

    //消息提示框
    private void showMessageDialog(String message) {
        mMessageDialog = new FreeUI_GeneralFragmentDialog();
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_prompt, null);
        Button btnConfirm = view.findViewById(R.id.btnConfirm);
        TextView tvTips = view.findViewById(R.id.tvTips);
        btnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMessageDialog.dismiss();
            }
        });
        tvTips.setText(message);
        mMessageDialog.setLayout(view);
//        mDieTypeDialog.getDialog().setCanceledOnTouchOutside(false);
        mMessageDialog.show(getSupportFragmentManager(), "ShowMessage");
        mMessageDialog.setCallBack(new FreeUI_CommonCallback() {
            @Override
            public void onSuccess() {
                mMessageDialog = null;
            }
        });

    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_query) {
            Bundle bundle = new Bundle();
            bundle.putString("EQPID", sEqpID);
            FreeApi_Utils.skipWithExtraIntent("header", bundle, getBaseContext(), MaterialExchangeActivity.class);

        } else if (v.getId() == R.id.btn_scan) {
            Intent intent = new Intent(mContext, FreeUI_QRCodeActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivityForResult(intent, 103);
        } else if (v.getId() == R.id.llMaterialLayout) {

            if (rvMaterialList.getVisibility() == View.GONE) {
                rvMaterialList.setVisibility(View.VISIBLE);
            } else {
                rvMaterialList.setVisibility(View.GONE);
            }
        } else if (v.getId() == R.id.tv_die_type) {
            showDieType();//选择芯片类型
        }else if(v.getId() == R.id.btn_deleteLot){
            if(tv_lot_id.getText().toString().trim() == null  || tv_lot_id.getText().toString().trim().length() == 0){
                showDialog("没有扫描批次,不能删除", false);
            }else{
                requestDeleteLotInfo(tv_lot_id.getText().toString().trim());
            }
        }else if(v.getId() == R.id.btn_con){
            getLotInfo(et_Lot.getText().toString().trim());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            if (data != null) {
                String barCode = data.getStringExtra("barCode");
                et_Lot.setText(barCode);
                et_Lot.setSelection(barCode.length());
                getLotInfo(barCode);//获取芯片类型

                //region 测试
//                mEqpInfoEntity.setDIE_TYPE("A;B;C");
//                showDieType();//显示晶片型号
                //endregion
            }
        }
    }

}